package com.zhanggod.jcheck.check;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * MEDICAL_BIRTH_CERTIFICATE
 * 不满2周岁婴儿的出生医学证明
 * @author zhangguodong
 */
public class BirthCertificate {

    private static List<String> birthLetterList = Arrays.asList("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    private static Integer  birthStart  = 2000;
    /**
     * 取两年之内的开头首字母
     * @param year
     * @return
     */
    private static List<String> getBirthStartLetter(Integer year, int size){
        List<String> resList = new ArrayList<>(size);
        int diffYear = year - 2000;
        int length = birthLetterList.size();
        int diffLetter = diffYear % length;
        if (diffLetter == 0) {
            // 占两头
            int diff = size - diffLetter;
            // 从后取一部分
            while (diff > 0){
                resList.add(birthLetterList.get(birthLetterList.size()-diff));
                diff --;
            }
        } else if (diffLetter < size) {
            // 占两头
            int diff = size - diffLetter;
            // 从后取一部分
            while (diff > 0){
                resList.add(birthLetterList.get(birthLetterList.size()-diff));
                diff --;
            }
            // 当前非第零位,且位置小于目标个数
            for (int i=0;i<diffLetter;i++) {
                resList.add(birthLetterList.get(i));
            }
        } else if (diffLetter > size) {
            // 顺序取前 size 个
            int diff = diffLetter - size;
            for (int i=0;i<diff;i++) {
                resList.add(birthLetterList.get(i));
            }
        }
        return resList;
    }

    public static void main(String[] args) {
        System.out.println(getBirthStartLetter(2026,3));
    }

}
